/**
 * 产品修改js
 */
var comValidform=null;
var returnStatus=false;
var activityUpdate={
	activityUE:null,
	key:null,
		
	startEvent:function(){
		 
		
		 
		activityUpdate.showInfo();
		
		comValidform=$(".com-addForm").Validform({
			datatype:{
				"m0-2" : /^[0-9]+(.[0-9]{1,2})?$/
			},
			tiptype:2,
			tipSweep:true,
			beforeSubmit:function(curform){
				var url = 'mgr/activityCtrl/updateStatus';
				var id = $('input[name="id"]').val(); 
				var status = $('select[name="status"]').val();

				var location =[];
				$('input[name="location"]:checked').each(function(){
					location.push($(this).val());
				});

				var params ={
			   		'id':id,
				    'status': status
				};

				params.location = location.toString();


				if((params.location == null || params.location == '') && params.status == 1){
					alert("请至少选择一个发布位置！");
					return false;
				}


				var cb = function(data){
					alert(data.msg);
					//成功返回
					if(data.resultCode==200){
						localStorage.removeItem(activityUpdate.key);
						//关闭窗口并刷新数据
						//art.dialog.close();
						returnStatus=true;
					}
				};
				sendApiNoLoadSync(url, params, cb, 'POST');
				return false;
			}
		});
	},
	
	showInfo:function(){
		
		var id = art.dialog.data('updId');
		activityUpdate.key = id + "_activity_Key";
		activityInfo = eval('(' + localStorage.getItem(activityUpdate.key) + ')');
		$("input[name='id']").val(activityInfo.id);
		$("input[name='name']").val(activityInfo.name);
		$("input[name='url']").val(activityInfo.url);
		 
		$("input[name='picAddress']").val(activityInfo.picAddress);
		$('select[name="status"]').val(activityInfo.status);

		if(activityInfo.location != null){
			if(activityInfo.location.indexOf("1") >= 0){
				$("input:checkbox[value='1']").attr('checked','true');
			}

			if(activityInfo.location.indexOf("2") >= 0){
				$("input:checkbox[value='2']").attr('checked','true');
			}
		}


	},
	
	init:function(){
		activityUpdate.startEvent();
	}
}
$(document).ready(function() {
	activityUpdate.init();
});
function submitForm(){
	comValidform.submitForm();
	return returnStatus;
}